package com.sit.estatemanagementserver.service;

import com.sit.estatemanagementserver.dao.RepairDao;
import com.sit.estatemanagementserver.enity.Repair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class RepairService {
    @Autowired
    RepairDao repairDao;

    // 新建报修
    public boolean addRepair(Repair repair) {
        // 无需修改
        return repairDao.addRepair(repair);
    }

    // 查看房间全部报修
    public List<Repair> getRepairByRoomNumber(String roomNumber) {
        // 无需修改
        return repairDao.getRepairsByRoom(roomNumber);
    }

    // 确认已处理报修
    public boolean finishRepair(String workOrderId) {
        Repair r = repairDao.getRepair(workOrderId);
        if (r == null) {
            return false;
        }
        // 重构: isProcessed() 和 setProcessed() 已改为 isHandled() 和 setHandled()
        if (r.isHandled()) {
            return false; // 已经处理过了，直接返回失败
        } else {
            r.setHandled(true);
            return repairDao.updateRepair(r);
        }
    }
}